package com.mui.dao.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import com.mui.dao.UserDao;
import com.mui.entity.UserInfo;
import com.mui.util.ObjectOpUtil;
import com.mui.util.StringUtil;

@Repository
public class UserDaoImpl implements UserDao {

	@Autowired  
	private JdbcTemplate jdbcTemplate;  
	
	@Override
	@SuppressWarnings("unchecked")
	public List<UserInfo> queryAllUser() {
		
		String sql = "select * from user";
		
		List<Map<String, Object>>  listMap = jdbcTemplate.queryForList(sql);
		
		UserInfo user = new UserInfo();
		
		return (List<UserInfo>)ObjectOpUtil.setObject(user, listMap);
	}

	@Override
	public UserInfo queryUser(UserInfo user) {
		
		String sql = "select * from user where 1=1";
		
		Map<String, Object> dataMap = ObjectOpUtil.objectToMap(user);
		
		sql = StringUtil.setSqlByMap(sql, dataMap);
		
		Map<String, Object> map = jdbcTemplate.queryForMap(sql);
		
		UserInfo userInfo = new UserInfo();
		
		return (UserInfo)ObjectOpUtil.setObject(userInfo, map);
	}

	@Override
	public int updataUser(UserInfo user, String type) {
		
		// TODO Auto-generated method stub
		String sql = "";
		
		return 0;
	}

}
